package features.advance.leetcode.interview;

/**
 *
 * 创建三个线程 一个打印a，一个打印n，一个打印t  循环交替打印antantant (编程语言不限)
 * @author LIN
 * @date 2021-05-11
 */
public class Practice {

    private volatile static int  lockA = 5;
    private volatile static int lockN = 5;
    private volatile static int lockT = 5;

    public static void main(String[] args) {

        Thread t1 = new Thread(){
            @Override
            public void run() {
                while(lockA >=1 && lockN>0 && lockT > 0){
                    if(lockA == lockN ){
                        System.out.print("a");
                        lockN--;
                    }
                }
            }
        };
        Thread t2 = new Thread(){
            @Override
            public void run() {
                while(lockN!=lockA - 1){

                }
                while(lockN >=0 && lockT>0){
                    if(lockN == lockT - 1){
                        System.out.print("n");
                        lockT--;
                    }
                }
            }
        };
        Thread t3 = new Thread(){
            @Override
            public void run() {
                while (lockT!=lockA - 1) {
                }
                while(lockT >= 0 && lockA > 0){
                    if(lockT == lockA - 1){
                        System.out.print("t");
                        lockA--;
                    }
                }
                System.out.println();
            }
        };
        t1.start();
        t2.start();
        t3.start();

    }
}
